const SysAuthTypeDao = appRequire(`dao/desktop/SysAuthTypeSequelizeDao.js`);
const uuid = require('uuid');
var dateFormat = require("dateformat");
// const SqliteUtil = require('../../modules/SqliteUtil');
class SysAuthTypeService {
    constructor() {

    }
    static async save(obj) {
        if (obj.id === '' || obj.id === undefined) {
            obj.id = uuid.v1();
            obj.createTime = dateFormat(new Date(), "yyyy-mm-dd HH:MM:ss");
            obj.updateTime = obj.createTime;
            await SysAuthTypeDao.saveOne(obj);
            return obj.id;
        } else {
            let dbObj = await SysAuthTypeDao.findById(obj.id);
            // SqliteUtil.dbObjectToEntity(dbObj,obj);
            obj.updateTime = dateFormat(new Date(), "yyyy-mm-dd HH:MM:ss");
            await SysAuthTypeDao.updateOne(obj);
        }
    }

    static async deleteOne(id) {
        return await SysAuthTypeDao.deleteById(id);
    }

    static async deleteMany(ids) {
        ids = JSON.parse(ids);
        return await SysAuthTypeDao.deleteMany(ids);
    }

    static async findOne(id) {
        return await SysAuthTypeDao.findOne(id);
    }

    static async findAllByType(type) {
        return await SysAuthTypeDao.findAllByType(type);
    }

    static async findAll() {
        return await SysAuthTypeDao.findAll();
    }

    static async findByPage(page) {
        page.pageNum = parseInt(page.pageNum);
        page.pageSize = parseInt(page.pageSize);
        page.searchParams = JSON.parse(page.searchParams);
        return await SysAuthTypeDao.findByPage(page);
    }

}
module.exports = SysAuthTypeService;